<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="__PUBLIC__/js/jquery.js"></script>
	<link href="__PUBLIC__/js/pagination/pagination.css" rel="stylesheet" type="text/css" />    
	<link href="__PUBLIC__/admin/css/layout.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript">
		var URL = "__URL__";

		var ctrl = function(name){
			this.elements = document.getElementsByName('id[]');
			this.length = this.elements.length;
		}
		ctrl.prototype = {
			reverse:function(){
				for(i=0;i<this.length;i++){
					this.elements[i].checked= !this.elements[i].checked;
				}
			},
			all:function(){
				for(i=0;i<this.length;i++){
					this.elements[i].checked = true;
				}
			},
			unAll:function(){
				for(i=0;i<this.length;i++){
					this.elements[i].checked = false;
				}
			},
			toggle:function(obj){
				this[obj.checked ? 'all' : 'unAll']();
			},
			del:function(id){
				if(id==undefined){
					id = [];
					for(i=0;i<this.length;i++){
						this.elements[i].checked && id.push(this.elements[i].value);
					}
					id = id.join(',');
				}
				if(confirm("你确定要卸载这个应用")){
					location.href = URL + "/del/id/"+id;
				}
			},
			edit:function(id){
				location.href = URL + "/edit/id/"+id;
			},
			set:function(id,status,t){
				//alert(id+"->"+status);
				location.href = URL + "/setStatus/id/"+id+"/s/"+status+"/t/"+t;
			}
		}
		var c = null;
	</script>
	</head>
	<body>
		<div id="container">
			<table class="tableborder" width="100%">
				<tbody>
					<tr class="top">
						<td class="border"></td>
					</tr>
					<tr>
						<th class="header">tips</th>
					</tr>
					<tr>
						<td class="tips">
							<ul>
								<li>ThinkSns 应用列表</li>
							</ul>
						</td>
					</tr>
					<tr class="bottom">
						<td class="border" colspan="5">&nbsp;</td>
					</tr>
				</tbody>
			</table>
			<table class="tableborder" width="100%">
				<tbody>
					<tr class="top">
						<td class="border" colspan="7"></td>
					</tr>
					<tr>
						<th class="header" colspan="7">标题</th>
					</tr>
					<tr class="label">
						<!-- <th><input type="checkbox" class="checkbox" onclick="c.toggle(this)" />删？</th> -->
						<th>图标</th>
						<th>名称</th>
						<th>作者</th>
						<th>状态</th>
						<th>设置</th>
                        <th>排序</th>
						<th>操作</th>
					</tr>
                    <script>
                        //up
                        function up(_this) {
                            //var up_id = order_id-1;
                           // $("#app_"+order_id).insertBefore("#app_"+up_id);
                           var order_id = $(_this).parent().parent().attr("alt");
                           
                           var prev_id = $("#app_"+order_id).prev().attr("id");
                           var id2 = $("#app_"+order_id).prev().attr("alt");
                           if(prev_id){

                              $.post("__URL__/doOrder",{id1:order_id,id2:id2},function(txt){
                                if(txt){
                                    var up = "#"+ prev_id;
                                    $("#app_"+order_id).insertBefore(up);
                                    //序号互换
                                    $(_this).parent().parent().attr("alt",id2);
                                    $(_this).parent().parent().attr("id","app_"+id2);

                                    $(_this).parent().parent().next().attr("alt",order_id);
                                    $(_this).parent().parent().next().attr("id","app_"+order_id);
                                }else{
                                    Error("排序失败!");
                                }
                             });

                           }

                        }

                         //down
                        function down(_this) {

                           var order_id = $(_this).parent().parent().attr("alt");

                           var prev_id = $("#app_"+order_id).next().attr("id");
                           var id2 = $("#app_"+order_id).next().attr("alt");
                           if(prev_id){

                              $.post("__URL__/doOrder",{id1:order_id,id2:id2},function(txt){
                                if(txt){
                                    var up = "#"+ prev_id;
                                    $("#app_"+order_id).insertAfter(up);

                                     //序号互换
                                    $(_this).parent().parent().attr("alt",id2);
                                    $(_this).parent().parent().attr("id","app_"+id2);

                                    $(_this).parent().parent().prev().attr("alt",order_id);
                                    $(_this).parent().parent().prev().attr("id","app_"+order_id);


                                }else{
                                    Error("排序失败!");
                                }
                             });

                           }

                        }

                    </script>
					<volist name="apps" id="app">
						<tr class="cell altbg1" id="app_{$app.order2}" alt="{$app.order2}" >
							<!-- <td><input type="checkbox" class="checkbox" name="id[]" value="1" /></td> -->
							<td><img src="{$app.icon}" alt="" /></td>
							<td>{$app.name}</td>
							<td>{$app.author}</td>
							<td>
								<php>
									switch($app["status"]){
										case  0 : echo "默认";break;
										case  1 : echo "可选";break;
										case  2 : echo "关闭";break;
									}
								</php>
							</td>
							<td>
							    <php>if($_GET["t"]!="default"){</php>
									<button type="button" onclick="c.set({$app.id},0,'{.t}')">设为默认</button>
								<php>}</php>
								<php>if($_GET["t"]!="choice"){</php>
									<button type="button" onclick="c.set({$app.id},1,'{.t}')">设为可选</button>
								<php>}</php>
								<php>if($_GET["t"]!="close"){</php>
									<button type="button" onclick="c.set({$app.id},2,'{.t}')">设为关闭</button>
								<php>}</php>
							</td>
                            <td>
                                <button type="button" onclick="up(this)">上移</button>
                                <button type="button" onclick="down(this)">下移</button>
                            </td>
							<td>
								<button type="button" onclick="c.edit({$app.id})">编辑</button>
								<button type="button" onclick="c.del({$app.id})">卸载</button>
							</td>
						</tr>
					</volist>




					<tr>
						<td class="footer" colspan="6">
						<div class="pagination">
							{$page}
						</div>
						</td>
					</tr>
	
<!-- 					<tr>
						<td class="footer" colspan="6">
							<button type="button" onclick="c.all()">全选</button>
							<button type="button" onclick="c.unAll()">全不选</button>
							<button type="button" onclick="c.reverse()">反选</button>
							<button type="button" onclick="c.del()">关闭</button>
						</td>
					</tr> -->
					<tr class="bottom">
						<td class="border" colspan="6">&nbsp;</td>
					</tr>
				</tbody>
			</table>
		</div>
		<script type="text/javascript">
			c = new ctrl('id[]');
		</script>
	</body>
</html>
